/**
 * 获取url
 * @param action
 * @returns
 */
function siteUrl(action, param){
	if(empty(action)){
		return getCurrent();
	}
	var preg = /^http[s]?/i;
	if(preg.test(action)){
		var url = action;
	}else{
		var host = getHost();
		var url = "http://"+host+"/"+action+".html";
	}
	
	if(!empty(param)){
		var i = 0;
		for(v in param){
			if(i==0){
				url += "?"+v+"="+encodeURIComponent(param[v])+"&";
			}else{
				url += v+"="+encodeURIComponent(param[v])+"&";
			}
			i++;
		}
	}
	return url;
}

/**
 * 判断某个值是否为空
 * @param val
 * @returns {Boolean}
 */
function empty(val){
	if(val == '' || val == undefined || val == null || val == false || typeof val == 'undefined') return true;
	return false;
}

/**
 * 获取主机
 * @returns
 */
function getHost(){
	var host = window.location.host;
	if(!empty(host)) return host;
	return document.domain;
}

/**
 * 获取带http的host函数
 * @returns
 */
function getHttpHost(){
	var host = getHost();
	var preg = /^http[s]?/i;
	if(!preg.test(host)){
		return host = "http://".host;
	}
	return host;
}

/**
 * 获取当前的url
 * @returns
 */
function getCurrent(){
	return window.location.href;
}

/**
 * 刷新当前页面
 */
function refresh(delay){
	var delay = delay ? delay : 0;
	if(delay > 0){
		setTimeout("window.location = getCurrent();", delay*1000);
	}else{
		window.location = getCurrent();
	}

}

/**
 * 解析字符串
 * @param str
 * @returns
 */
function evalJson(str){
	return eval("("+str+")");
}

/**
 * js跳转页面
 * @param url
 */
function redirect(url, param){
	if(empty(param))
		param = {};
	var preg = /^http[s]?/i;
	if(! preg.test(url))
		url = siteUrl(url, param);
	window.location.href=url;
}

/**
 * 縮圖
 * @param ImgD
 * @param w
 * @param h
 */
function setImgSize(ImgD,w,h){
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		if(image.width/image.height>= w/h){
			if(image.width>h){
				ImgD.width=w;
				ImgD.height=(image.height*h)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		else{
			if(image.height>h){
				ImgD.height=h;
				ImgD.width=(image.width*h)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
}

/**
 * 获取cookie值
 * @param key
 * @returns
 */
function getCookie(key){
	//增加一级解密处理
	if(empty(key)) return null;
	return $.cookie.get(key);
}

/**
 * 设置cookie
 * @param key
 * @param value
 * @param domain
 * @param path
 * @param hour
 * @returns
 */
function setCookie(key, value, domain, path, hour){
	//增加一级加密处理
	return $.cookie.set(key, value, domain, path, hour);
}

/**
 * 删除cookie操作
 * @param key
 * @param domain
 * @param path
 */
function cleanCookie(key, domain, path){
	if(empty(key))
		$.cookie.clean();
	else{
		$.cookie.del(key, domain, path);
	}
}

/**
 *获取当前日期加时间(如:2009-06-12 12:00)
 *
*/
function CurentTime() {
    var now = new Date();

    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日

    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var ss = now.getSeconds();           //秒

    var clock = year + "-";

    if (month < 10) {
        clock += "0";
    }
    clock += month + "-";

    if (day < 10) {
        clock += "0";
    }
    clock += day + " ";

    if (hh < 10) {
        clock += "0";
    }
    clock += hh + ":";

    if (mm < 10) {
        clock += '0';
    }
    clock += mm + ":";

    if (ss < 10) {
        clock += "0";
    }
    clock += ss;

    return (clock);
}